<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!DOCTYPE html>
<html lang="zh-cn" style="height: 100%">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <title><?=VIEW_TITLE?></title>
    <link href="<?php echo base_url('/assets/bs/'); ?>css/bootstrap.min.css" rel="stylesheet">
    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
</head>
<body>
<?php $this->load->view('simple_header.php'); ?>
<div class="container-fluid">
    <div id="main_div" class="row">
        <div class="title" style="line-height:70px;font-size:36px;text-align: center;"><?=VIEW_TITLE?></div>
        <div class="col-sm-4 col-md-4">
        </div>
        <div class="col-sm-4 col-md-4" style="">
            <form class="form-horizontal" method="post" onsubmit="return false;">
                <div class="form-group">
                    <div class="col-sm-12 col-md-12">
                        <input type="text" class="form-control" id="username" placeholder="请输入手机号或者邮箱" name="password">
                        <input style="margin-top: 10px" type="password" class="form-control" id="password"
                               placeholder="密码" name="password">
                        <input hidden="hidden" value="" name="p_token">
                    </div>
                </div>
                <div style="margin-top: -10px;height: 20px;">
                    <a href="<?php echo site_url('/admin/cPassword') ?>"
                       style="display: block;float: right;font-size: 10px;">忘记密码</a>
                </div>
                <div class="form-group">
                    <div class="col-sm-12 col-md-12" style="margin-top: 10px">
                        <div class="col-sm-6 col-md-6 col-xs-6" style="padding-left: 0;">
                            <button class="btn btn-success col-sm-6 col-md-6" onclick="login()" style="width: 100%">登录
                            </button>
                        </div>
                        <div class="col-sm-6 col-md-6 col-xs-6" style="padding-right: 0">
                            <a href="<?php echo site_url('/admin/register') ?>" style="width: 100%"
                               class="btn btn-primary">注册</a>
                        </div>
                    </div>
                </div>
            </form>
            <div class="alert alert-danger" role="alert" id="warn" style="display: none;"></div>
            <h6 style="text-align: center">
                译之网 鲁ICP备15042617号-2
            </h6>
        </div>
        <div class="col-sm-4 col-md-4">
        </div>
    </div>
</div>
<?php
$this->load->view('footer.php');
?>
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script src="<?php echo base_url('/assets/bs/'); ?>js/bootstrap.min.js"></script>
<script>
    var w_width = document.documentElement.clientWidth;
    var w_height = document.documentElement.clientHeight;
    var main_div_height = w_height - 300;
    $('#main_div').height(main_div_height + 'px');
    $('.title').css('margin-top', main_div_height * 0.1 + 'px');

    function login() {
        var username = $('#username').val();
        var password = $('#password').val();
        if (username == '' || password == '') {
            alert('账号密码不能留空!');
            return;
        }
        $.ajax({
            url: '<?php echo site_url('/Admin/loginAttestation')?>',
            type: 'post',
            dataType: 'json',
            data: {
                username: username,
                password: password,
                token: '<?php echo $token?>'
            },
            success: function (data) {
                console.log(data);
                var warn_text = '';
                if (data == 4) {
                    location.reload();
                    return;
                } else if (data == 3) {
                    warn_text = 'warn : 用户名或密码不正确!';
                } else if (data == 2) {
                    warn_text = 'warn : 用户名或密码不正确!';
                } else if (data == 1) {
                    window.location.href = '<?php echo site_url('/admin/index')?>';
                    return;
                } else if (data == 5) {
                    warn_text = 'warn : 账号已被停用!';
                }else{
                    warn_text = 'warn : 登录失败,请刷新再试!';
                }
                $('#warn').text(warn_text);
                $('#warn').show();
            }
        });
    }
</script>
</body>
</html>